<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>
  Module: Consistency
  
    &mdash; FSelector Documentation
  
</title>

  <link rel="stylesheet" href="css/style.css" type="text/css" media="screen" charset="utf-8" />

  <link rel="stylesheet" href="css/common.css" type="text/css" media="screen" charset="utf-8" />

<script type="text/javascript" charset="utf-8">
  relpath = '';
  if (relpath != '') relpath += '/';
</script>

  <script type="text/javascript" charset="utf-8" src="js/jquery.js"></script>

  <script type="text/javascript" charset="utf-8" src="js/app.js"></script>


  </head>
  <body>
    <script type="text/javascript" charset="utf-8">
      if (window.top.frames.main) document.body.className = 'frames';
    </script>
    
    <div id="header">
      <div id="menu">
  
    <a href="_index.html">Index (C)</a> &raquo; 
    
    
    <span class="title">Consistency</span>
  
  
  <div class="noframes"><span class="title">(</span><a href="." target="_top">no frames</a><span class="title">)</span></div>
</div>

      <div id="search">
  
    <a id="class_list_link" href="#">Class List</a>
  
    <a id="method_list_link" href="#">Method List</a>
  
    <a id="file_list_link" href="#">File List</a>
  
</div>
      <div class="clear"></div>
    </div>
    
    <iframe id="search_frame"></iframe>
    
    <div id="content"><h1>Module: Consistency
  
  
  
</h1>

<dl class="box">
  
  
    
  
    
  
  
    <dt class="r1">Included in:</dt>
    <dd class="r1"><span class='object_link'><a href="Discretizer.html" title="Discretizer (module)">Discretizer</a></span>, <span class='object_link'><a href="FSelector/INTERACT.html" title="FSelector::INTERACT (class)">FSelector::INTERACT</a></span>, <span class='object_link'><a href="FSelector/LasVegasFilter.html" title="FSelector::LasVegasFilter (class)">FSelector::LasVegasFilter</a></span>, <span class='object_link'><a href="FSelector/LasVegasIncremental.html" title="FSelector::LasVegasIncremental (class)">FSelector::LasVegasIncremental</a></span></dd>
    
  
  
    <dt class="r2 last">Defined in:</dt>
    <dd class="r2 last">lib/fselector/consistency.rb</dd>
  
</dl>
<div class="clear"></div>

<h2>Overview</h2><div class="docstring">
  <div class="discussion">
    <p>data consistency-related functions</p>


  </div>
</div>
<div class="tags">
  

</div>






  
    <h2>
      Instance Method Summary
      <small>(<a href="#" class="summary_toggle">collapse</a>)</small>
    </h2>

    <ul class="summary">
      
        <li class="public ">
  <span class="summary_signature">
    
      <a href="#get_instance_count-instance_method" title="#get_instance_count (instance method)">- (Hash) <strong>get_instance_count</strong>(my_data = nil) </a>
    

    
  </span>
  
  
  
  
  
  

  
    <span class="summary_desc"><div class='inline'><p>get the counts of each (unique) instance (without class label)<br>
for each class, the resulting Hash table, as suggested by Zheng Zhao 
and Huan Liu, looks like:.</p>
</div></span>
  
</li>

      
        <li class="public ">
  <span class="summary_signature">
    
      <a href="#get_IR-instance_method" title="#get_IR (instance method)">- (Float) <strong>get_IR</strong>(my_data = nil) </a>
    

    
  </span>
  
  
  
  
  
  

  
    <span class="summary_desc"><div class='inline'><p>get data inconsistency rate, suitable for single-time calculation.</p>
</div></span>
  
</li>

      
        <li class="public ">
  <span class="summary_signature">
    
      <a href="#get_IR_by_count-instance_method" title="#get_IR_by_count (instance method)">- (Float) <strong>get_IR_by_count</strong>(inst_cnt) </a>
    

    
  </span>
  
  
  
  
  
  

  
    <span class="summary_desc"><div class='inline'><p>get data inconsistency rate based on the instance count in Hash table.</p>
</div></span>
  
</li>

      
        <li class="public ">
  <span class="summary_signature">
    
      <a href="#get_IR_by_feature-instance_method" title="#get_IR_by_feature (instance method)">- (Float) <strong>get_IR_by_feature</strong>(inst_cnt, feats) </a>
    

    
  </span>
  
  
  
  
  
  

  
    <span class="summary_desc"><div class='inline'><p>get data inconsistency rate for given features.</p>
</div></span>
  
</li>

      
    </ul>
  



  <div id="instance_method_details" class="method_details_list">
    <h2>Instance Method Details</h2>
    
    
      <div class="method_details first">
  <p class="signature first" id="get_instance_count-instance_method">
  
    - (<tt>Hash</tt>) <strong>get_instance_count</strong>(my_data = nil) 
  

  
</p><div class="docstring">
  <div class="discussion">
    
  <div class="note notetag">
    <strong>Note:</strong> 
    <div class='inline'><p>intended for mulitple calculations, because chekcing data inconsistency 
rate based on the resultant Hash table is very efficient and avoids 
reconstructing new data structure and repetitive counting. For instead, 
you only rebuild the Hash keys and merge relevant counts</p>
</div>
  </div>

<p>get the counts of each (unique) instance (without class label)<br>
for each class, the resulting Hash table, as suggested by Zheng Zhao 
and Huan Liu, looks like:</p>

<pre class="code ruby"><code>{
 'f1:v1|f2:v2|...|fn:vn|' =&gt; {k1=&gt;c1, k2=&gt;c2, ..., kn=&gt;cn},
  ...
}

where we use the (sorted) features and their values to construct 
the key for Hash table, i.e., v_i is the value for feature f_i. 
Note the symbol : separates a feature and its value, and the 
symbol | separates a feature-value pair. In other words, they 
should not appear in any feature or its value. If so, please 
replace them with other symbols in advance. The c_i is the 
instance count for class k_i 
</code></pre>

<p>ref: <a href="http://www.public.asu.edu/%7Ehuanliu/papers/ijcai07.pdf">Searching for Interacting Features</a></p>


  </div>
</div>
<div class="tags">
  <h3>Parameters:</h3>
<ul class="param">
  
    <li>
      
        <span class='name'>my_data</span>
      
      
        <span class='type'>(<tt>Hash</tt>)</span>
      
      
        <em class="default">(defaults to: <tt>nil</tt>)</em>
      
      
        &mdash;
        <div class='inline'><p>data of interest, use internal data by default</p>
</div>
      
    </li>
  
</ul>

<h3>Returns:</h3>
<ul class="return">
  
    <li>
      
      
        <span class='type'>(<tt>Hash</tt>)</span>
      
      
      
        &mdash;
        <div class='inline'><p>counts of each (unique) instance for each class</p>
</div>
      
    </li>
  
</ul>

</div><table class="source_code">
  <tr>
    <td>
      <pre class="lines">


32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48</pre>
    </td>
    <td>
      <pre class="code"><span class="info file"># File 'lib/fselector/consistency.rb', line 32</span>

<span class='kw'>def</span> <span class='id identifier rubyid_get_instance_count'>get_instance_count</span><span class='lparen'>(</span><span class='id identifier rubyid_my_data'>my_data</span><span class='op'>=</span><span class='kw'>nil</span><span class='rparen'>)</span>
  <span class='id identifier rubyid_my_data'>my_data</span> <span class='op'>||=</span> <span class='id identifier rubyid_get_data'>get_data</span> <span class='comment'># use internal data by default
</span>  <span class='id identifier rubyid_inst_cnt'>inst_cnt</span> <span class='op'>=</span> <span class='lbrace'>{</span><span class='rbrace'>}</span>
  
  <span class='id identifier rubyid_my_data'>my_data</span><span class='period'>.</span><span class='id identifier rubyid_each'>each</span> <span class='kw'>do</span> <span class='op'>|</span><span class='id identifier rubyid_k'>k</span><span class='comma'>,</span> <span class='id identifier rubyid_ss'>ss</span><span class='op'>|</span>
    <span class='id identifier rubyid_ss'>ss</span><span class='period'>.</span><span class='id identifier rubyid_each'>each</span> <span class='kw'>do</span> <span class='op'>|</span><span class='id identifier rubyid_s'>s</span><span class='op'>|</span>
      <span class='comment'># sort make sure a same key
</span>      <span class='comment'># : separates a feature and its value
</span>      <span class='comment'># | separates a feature-value pair
</span>      <span class='id identifier rubyid_key'>key</span> <span class='op'>=</span> <span class='id identifier rubyid_s'>s</span><span class='period'>.</span><span class='id identifier rubyid_keys'>keys</span><span class='period'>.</span><span class='id identifier rubyid_sort'>sort</span><span class='period'>.</span><span class='id identifier rubyid_collect'>collect</span> <span class='lbrace'>{</span> <span class='op'>|</span><span class='id identifier rubyid_f'>f</span><span class='op'>|</span> <span class='tstring'><span class='tstring_beg'>&quot;</span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_f'>f</span><span class='rbrace'>}</span><span class='tstring_content'>:</span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_s'>s</span><span class='lbracket'>[</span><span class='id identifier rubyid_f'>f</span><span class='rbracket'>]</span><span class='rbrace'>}</span><span class='tstring_content'>|</span><span class='tstring_end'>&quot;</span></span><span class='rbrace'>}</span><span class='period'>.</span><span class='id identifier rubyid_join'>join</span>
      <span class='id identifier rubyid_inst_cnt'>inst_cnt</span><span class='lbracket'>[</span><span class='id identifier rubyid_key'>key</span><span class='rbracket'>]</span> <span class='op'>||=</span> <span class='const'>Hash</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span><span class='lparen'>(</span><span class='int'>0</span><span class='rparen'>)</span>
      <span class='id identifier rubyid_inst_cnt'>inst_cnt</span><span class='lbracket'>[</span><span class='id identifier rubyid_key'>key</span><span class='rbracket'>]</span><span class='lbracket'>[</span><span class='id identifier rubyid_k'>k</span><span class='rbracket'>]</span> <span class='op'>+=</span> <span class='int'>1</span> <span class='comment'># for key in class k
</span>    <span class='kw'>end</span>
  <span class='kw'>end</span>
  
  <span class='id identifier rubyid_inst_cnt'>inst_cnt</span>
<span class='kw'>end</span></pre>
    </td>
  </tr>
</table>
</div>
    
      <div class="method_details ">
  <p class="signature " id="get_IR-instance_method">
  
    - (<tt>Float</tt>) <strong>get_IR</strong>(my_data = nil) 
  

  
</p><div class="docstring">
  <div class="discussion">
    <p>get data inconsistency rate, suitable for single-time calculation</p>


  </div>
</div>
<div class="tags">
  <h3>Parameters:</h3>
<ul class="param">
  
    <li>
      
        <span class='name'>my_data</span>
      
      
        <span class='type'>(<tt>Hash</tt>)</span>
      
      
        <em class="default">(defaults to: <tt>nil</tt>)</em>
      
      
        &mdash;
        <div class='inline'><p>data of interest, use internal data by default</p>
</div>
      
    </li>
  
</ul>

<h3>Returns:</h3>
<ul class="return">
  
    <li>
      
      
        <span class='type'>(<tt>Float</tt>)</span>
      
      
      
        &mdash;
        <div class='inline'><p>data inconsistency rate</p>
</div>
      
    </li>
  
</ul>

</div><table class="source_code">
  <tr>
    <td>
      <pre class="lines">


108
109
110
111
112
113
114
115</pre>
    </td>
    <td>
      <pre class="code"><span class="info file"># File 'lib/fselector/consistency.rb', line 108</span>

<span class='kw'>def</span> <span class='id identifier rubyid_get_IR'>get_IR</span><span class='lparen'>(</span><span class='id identifier rubyid_my_data'>my_data</span><span class='op'>=</span><span class='kw'>nil</span><span class='rparen'>)</span>
  <span class='id identifier rubyid_my_data'>my_data</span> <span class='op'>||=</span> <span class='id identifier rubyid_get_data'>get_data</span> <span class='comment'># use internal data by default
</span>  <span class='id identifier rubyid_inst_cnt'>inst_cnt</span> <span class='op'>=</span> <span class='id identifier rubyid_get_instance_count'>get_instance_count</span><span class='lparen'>(</span><span class='id identifier rubyid_my_data'>my_data</span><span class='rparen'>)</span>
  <span class='id identifier rubyid_ir'>ir</span> <span class='op'>=</span> <span class='id identifier rubyid_get_IR_by_count'>get_IR_by_count</span><span class='lparen'>(</span><span class='id identifier rubyid_inst_cnt'>inst_cnt</span><span class='rparen'>)</span>
  
  <span class='comment'># inconsistency rate
</span>  <span class='id identifier rubyid_ir'>ir</span>
<span class='kw'>end</span></pre>
    </td>
  </tr>
</table>
</div>
    
      <div class="method_details ">
  <p class="signature " id="get_IR_by_count-instance_method">
  
    - (<tt>Float</tt>) <strong>get_IR_by_count</strong>(inst_cnt) 
  

  
</p><div class="docstring">
  <div class="discussion">
    <p>get data inconsistency rate based on the instance count in Hash table</p>


  </div>
</div>
<div class="tags">
  <h3>Parameters:</h3>
<ul class="param">
  
    <li>
      
        <span class='name'>inst_cnt</span>
      
      
        <span class='type'>(<tt>Hash</tt>)</span>
      
      
      
        &mdash;
        <div class='inline'><p>the counts of each (unique) instance (without 
class label) for each class</p>
</div>
      
    </li>
  
</ul>

<h3>Returns:</h3>
<ul class="return">
  
    <li>
      
      
        <span class='type'>(<tt>Float</tt>)</span>
      
      
      
        &mdash;
        <div class='inline'><p>data inconsistency rate</p>
</div>
      
    </li>
  
</ul>

</div><table class="source_code">
  <tr>
    <td>
      <pre class="lines">


58
59
60
61
62
63
64
65
66
67
68
69</pre>
    </td>
    <td>
      <pre class="code"><span class="info file"># File 'lib/fselector/consistency.rb', line 58</span>

<span class='kw'>def</span> <span class='id identifier rubyid_get_IR_by_count'>get_IR_by_count</span><span class='lparen'>(</span><span class='id identifier rubyid_inst_cnt'>inst_cnt</span><span class='rparen'>)</span>    
  <span class='id identifier rubyid_incon'>incon</span><span class='comma'>,</span> <span class='id identifier rubyid_sample_size'>sample_size</span> <span class='op'>=</span> <span class='float'>0.0</span><span class='comma'>,</span> <span class='float'>0.0</span>
  
  <span class='id identifier rubyid_inst_cnt'>inst_cnt</span><span class='period'>.</span><span class='id identifier rubyid_values'>values</span><span class='period'>.</span><span class='id identifier rubyid_each'>each</span> <span class='kw'>do</span> <span class='op'>|</span><span class='id identifier rubyid_hcnt'>hcnt</span><span class='op'>|</span>
    <span class='id identifier rubyid_cnt'>cnt</span> <span class='op'>=</span> <span class='id identifier rubyid_hcnt'>hcnt</span><span class='period'>.</span><span class='id identifier rubyid_values'>values</span>
    <span class='id identifier rubyid_incon'>incon</span> <span class='op'>+=</span> <span class='id identifier rubyid_cnt'>cnt</span><span class='period'>.</span><span class='id identifier rubyid_sum'>sum</span><span class='op'>-</span><span class='id identifier rubyid_cnt'>cnt</span><span class='period'>.</span><span class='id identifier rubyid_max'>max</span>
    <span class='id identifier rubyid_sample_size'>sample_size</span> <span class='op'>+=</span> <span class='id identifier rubyid_cnt'>cnt</span><span class='period'>.</span><span class='id identifier rubyid_sum'>sum</span>
  <span class='kw'>end</span>
  
  <span class='comment'># inconsistency rate
</span>  <span class='lparen'>(</span><span class='id identifier rubyid_sample_size'>sample_size</span><span class='period'>.</span><span class='id identifier rubyid_zero?'>zero?</span><span class='rparen'>)</span> <span class='op'>?</span> <span class='float'>0.0</span> <span class='op'>:</span> <span class='id identifier rubyid_incon'>incon</span><span class='op'>/</span><span class='id identifier rubyid_sample_size'>sample_size</span>
<span class='kw'>end</span></pre>
    </td>
  </tr>
</table>
</div>
    
      <div class="method_details ">
  <p class="signature " id="get_IR_by_feature-instance_method">
  
    - (<tt>Float</tt>) <strong>get_IR_by_feature</strong>(inst_cnt, feats) 
  

  
</p><div class="docstring">
  <div class="discussion">
    <p>get data inconsistency rate for given features</p>


  </div>
</div>
<div class="tags">
  <h3>Parameters:</h3>
<ul class="param">
  
    <li>
      
        <span class='name'>inst_cnt</span>
      
      
        <span class='type'>(<tt>Hash</tt>)</span>
      
      
      
        &mdash;
        <div class='inline'><p>source Hash table of instance count</p>
</div>
      
    </li>
  
    <li>
      
        <span class='name'>feats</span>
      
      
        <span class='type'>(<tt><span class='object_link'><a href="Array.html" title="Array (class)">Array</a></span></tt>)</span>
      
      
      
        &mdash;
        <div class='inline'><p>consider only these features</p>
</div>
      
    </li>
  
</ul>

<h3>Returns:</h3>
<ul class="return">
  
    <li>
      
      
        <span class='type'>(<tt>Float</tt>)</span>
      
      
      
        &mdash;
        <div class='inline'><p>data inconsistency rate</p>
</div>
      
    </li>
  
</ul>

</div><table class="source_code">
  <tr>
    <td>
      <pre class="lines">


79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99</pre>
    </td>
    <td>
      <pre class="code"><span class="info file"># File 'lib/fselector/consistency.rb', line 79</span>

<span class='kw'>def</span> <span class='id identifier rubyid_get_IR_by_feature'>get_IR_by_feature</span><span class='lparen'>(</span><span class='id identifier rubyid_inst_cnt'>inst_cnt</span><span class='comma'>,</span> <span class='id identifier rubyid_feats'>feats</span><span class='rparen'>)</span>
  <span class='kw'>return</span> <span class='float'>0.0</span> <span class='kw'>if</span> <span class='id identifier rubyid_feats'>feats</span><span class='period'>.</span><span class='id identifier rubyid_empty?'>empty?</span>
  
  <span class='comment'># build new inst_count for feats
</span>  <span class='id identifier rubyid_inst_cnt_new'>inst_cnt_new</span> <span class='op'>=</span> <span class='lbrace'>{</span><span class='rbrace'>}</span>
  
  <span class='id identifier rubyid_inst_cnt'>inst_cnt</span><span class='period'>.</span><span class='id identifier rubyid_each'>each</span> <span class='kw'>do</span> <span class='op'>|</span><span class='id identifier rubyid_key'>key</span><span class='comma'>,</span> <span class='id identifier rubyid_hcnt'>hcnt</span><span class='op'>|</span>
    <span class='id identifier rubyid_key_new'>key_new</span> <span class='op'>=</span> <span class='id identifier rubyid_feats'>feats</span><span class='period'>.</span><span class='id identifier rubyid_sort'>sort</span><span class='period'>.</span><span class='id identifier rubyid_collect'>collect</span> <span class='lbrace'>{</span> <span class='op'>|</span><span class='id identifier rubyid_f'>f</span><span class='op'>|</span>
      <span class='id identifier rubyid_match_data'>match_data</span> <span class='op'>=</span> <span class='id identifier rubyid_key'>key</span><span class='period'>.</span><span class='id identifier rubyid_match'>match</span><span class='lparen'>(</span><span class='tstring'><span class='regexp_beg'>/</span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_f'>f</span><span class='rbrace'>}</span><span class='tstring_content'>:.*?\|</span><span class='regexp_end'>/</span></span><span class='rparen'>)</span>
      <span class='id identifier rubyid_match_data'>match_data</span><span class='lbracket'>[</span><span class='int'>0</span><span class='rbracket'>]</span> <span class='kw'>if</span> <span class='id identifier rubyid_match_data'>match_data</span>
    <span class='rbrace'>}</span><span class='period'>.</span><span class='id identifier rubyid_compact'>compact</span><span class='period'>.</span><span class='id identifier rubyid_join'>join</span> <span class='comment'># remove nil entry and join
</span>    <span class='kw'>next</span> <span class='kw'>if</span> <span class='id identifier rubyid_key_new'>key_new</span><span class='period'>.</span><span class='id identifier rubyid_empty?'>empty?</span>
    
    <span class='id identifier rubyid_hcnt_new'>hcnt_new</span> <span class='op'>=</span> <span class='id identifier rubyid_inst_cnt_new'>inst_cnt_new</span><span class='lbracket'>[</span><span class='id identifier rubyid_key_new'>key_new</span><span class='rbracket'>]</span> <span class='op'>||</span> <span class='const'>Hash</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span><span class='lparen'>(</span><span class='int'>0</span><span class='rparen'>)</span>
    <span class='comment'># merge cnts
</span>    <span class='id identifier rubyid_inst_cnt_new'>inst_cnt_new</span><span class='lbracket'>[</span><span class='id identifier rubyid_key_new'>key_new</span><span class='rbracket'>]</span> <span class='op'>=</span> <span class='id identifier rubyid_hcnt_new'>hcnt_new</span><span class='period'>.</span><span class='id identifier rubyid_merge'>merge</span><span class='lparen'>(</span><span class='id identifier rubyid_hcnt'>hcnt</span><span class='rparen'>)</span> <span class='lbrace'>{</span> <span class='op'>|</span><span class='id identifier rubyid_kk'>kk</span><span class='comma'>,</span> <span class='id identifier rubyid_v1'>v1</span><span class='comma'>,</span> <span class='id identifier rubyid_v2'>v2</span><span class='op'>|</span> <span class='id identifier rubyid_v1'>v1</span><span class='op'>+</span><span class='id identifier rubyid_v2'>v2</span> <span class='rbrace'>}</span>
  <span class='kw'>end</span>
  
  <span class='comment'># inconsistency rate
</span>  <span class='id identifier rubyid_get_IR_by_count'>get_IR_by_count</span><span class='lparen'>(</span><span class='id identifier rubyid_inst_cnt_new'>inst_cnt_new</span><span class='rparen'>)</span>
<span class='kw'>end</span></pre>
    </td>
  </tr>
</table>
</div>
    
  </div>

</div>
    
    <div id="footer">
  Generated on Mon Nov  5 11:19:44 2012 by 
  <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
  0.7.5 (ruby-1.9.3).
</div>

  </body>
</html>